package com.dw.common.utils;

import com.dw.common.entitys.BaseResponse;
import com.dw.common.enums.ErrorCode;
import com.dw.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
public class ParseClientResultUtils {

    public static <T> T parseClientResult(BaseResponse<T> clientResult) {
        log.info("feign传来的参数:{}", clientResult);
        int code = clientResult.getCode();
        if(code == ErrorCode.SUCCESS.getCode()){
            return clientResult.getData();
        }
        log.error("feign传来的参数 error:{}", clientResult);
        throw new BusinessException(code, clientResult.getMessage());
    }
}
